/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-10 10:57:39
 * @LastEditors: 颜礼田 2564217790@qq.com
 * @LastEditTime: 2024-09-10 11:59:29
 * @FilePath: /webServer/src/model/department/department.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Column,
  Entity,
  OneToMany,
  Tree,
  TreeChildren,
  TreeParent,
} from 'typeorm';
import { DBColumns } from '../';
import { DepartmentSchema, UserSchema } from '../../schema';
import { User } from '../user/user';

@Entity('department')
@Tree('closure-table')
export class Department extends DBColumns implements DepartmentSchema {
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '部门名称',
  })
  deptName: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '部门编码',
  })
  deptCode: string;

  @TreeParent()
  parent?: DepartmentSchema;

  @TreeChildren()
  children?: DepartmentSchema[];

  @OneToMany(() => User, user => user.dept)
  user?: UserSchema[];
}
